﻿namespace com.stifel.ServerBuildMgmtDao
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Mail;
    using System.Xml.Serialization;

    using com.stifel.common;
    using com.stifel.Extensions.ObjectExtensions;
    using com.stifel.Extensions.StringExtensions;
    using com.stifel.GlobalDao;
    using com.stifel.SharePoint;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Linq;

    using Adconfigstatus = ServerBuildMgmtDao.ADConfigStatus;

    using Approvalstatus = ServerBuildMgmtDao.ApprovalStatus;

    using Avconfigstatus = ServerBuildMgmtDao.AVConfigStatus;

    using Backupconfigstatus = ServerBuildMgmtDao.BackupConfigStatus;

    using Buildstatus = ServerBuildMgmtDao.BuildStatus;

    using Monitoringconfigstatus = ServerBuildMgmtDao.MonitorConfigStatus;

    using Patchconfigstatus = ServerBuildMgmtDao.PatchConfigStatus;

    using Requeststatus = ServerBuildMgmtDao.RequestorStatus;

    [Serializable]
    public class SerializableStifelOS : IStifelOS, IItem
    {
        #region Properties

        public bool? Active
        {
            get;
            set;
        }

        public SPUserInfoExpanded Author
        {
            get;
            set;
        }

        public System.DateTime Created
        {
            get;
            set;
        }

        public bool? Default
        {
            get;
            set;
        }

        public double? DftCPU
        {
            get;
            set;
        }

        public string DftHardDriveLabel
        {
            get;
            set;
        }

        public string DftHardDriveName
        {
            get;
            set;
        }

        public double? DftHardDrives
        {
            get;
            set;
        }

        public double? DftHDSizeGB
        {
            get;
            set;
        }

        public double? DftMemoryGB
        {
            get;
            set;
        }

        //public double? DftNetworkConnections
        //{
        //    get;
        //    set;
        //}

        public SPUserInfoExpanded Editor
        {
            get;
            set;
        }

        public int? Id
        {
            get;
            set;
        }

        public string InternalOSName
        {
            get;
            set;
        }

        public bool? LegacyOS
        {
            get;
            set;
        }

        public double? MaxCPU
        {
            get;
            set;
        }

        public double? MaxHardDrives
        {
            get;
            set;
        }

        public double? MaxMemoryGB
        {
            get;
            set;
        }

        public double? MaxNetworkConnections
        {
            get;
            set;
        }

        public System.DateTime Modified
        {
            get;
            set;
        }

        public string OSName
        {
            get;
            set;
        }

        public string Path
        {
            get;
            set;
        }

        public bool? Server
        {
            get;
            set;
        }

        [XmlIgnore]
        public List<ServerRole> ServerRoles
        {
            get;
            set;
        }

        //public SerializableDictionary<int, string> SimpleRoles
        //{
        //    get;
        //    set;
        //}

        public string Title
        {
            get;
            set;
        }

        public System.Guid UniqueId
        {
            get;
            set;
        }

        public int? Version
        {
            get;
            set;
        }

        #endregion Properties
    }

    public class ServerRole
    {
        #region Fields

        List<string> _Subroles;

        #endregion Fields

        #region Properties

        public int Id
        {
            get;
            set;
        }

        public List<string> Subroles
        {
            get
            {
                if ( _Subroles == null )
                    _Subroles = new List<string>( );
                return _Subroles;
            }
            set
            {
                _Subroles = value;
            }
        }

        public string Title
        {
            get;
            set;
        }

        #endregion Properties
    }

    public partial class StifelNetworkConnectionType
    {
        #region Fields

        public List<string> vlanCluster = new List<string>();

        #endregion Fields

        #region Methods

        public StifelNetworkConnectionTypeSerializable ToSrializable( )
        {
            return new StifelNetworkConnectionTypeSerializable
            {
                ncType = Title,
                ncTypeDft = NetworkConnectionTypeDescrRqd.Value,
                ncTypeDscReq = NetworkConnectionTypeDescrRqd.Value,
                ncTypeSrv = NetworkConnectionTypeServer.Value,
                ncTypeVlanClusters = vlanCluster,
            };
        }

        #endregion Methods
    }

    [Serializable]
    public class StifelNetworkConnectionTypeSerializable
    {
        #region Properties

        public string ncType
        {
            get;
            set;
        }

        public bool ncTypeDft
        {
            get;
            set;
        }

        public bool ncTypeDscReq
        {
            get;
            set;
        }

        public bool ncTypeSrv
        {
            get;
            set;
        }

        public List<string> ncTypeVlanClusters
        {
            get;
            set;
        }

        #endregion Properties
    }

    public partial class StifelOS : ICustomMapping, IStifelOS, IItem
    {
        #region Fields

        List<ServerRole> _ServerRoles;
        //SerializableDictionary<int, string> _SimpleRoles;

        #endregion Fields

        #region Properties

        public List<ServerRole> ServerRoles
        {
            get
            {
                if ( _ServerRoles == null )
                {
                    _ServerRoles = new List<ServerRole>( );
                }
                return _ServerRoles;
            }
            set
            {
                _ServerRoles = value;
            }
        }

        //[Obsolete( "Use ServerRoles property instead." )]
        //public SerializableDictionary<int, string> SimpleRoles
        //{
        //    get
        //    {
        //        if ( _SimpleRoles == null )
        //        {
        //            _SimpleRoles = new SerializableDictionary<int, string>( );
        //            for ( int i = 0; i < RolesId.Count; i++ )
        //            {
        //                if ( RolesId[ i ].HasValue )
        //                    _SimpleRoles.Add( RolesId[ i ].Value, RolesTitle[ i ] );
        //            }
        //        }
        //        return _SimpleRoles;
        //    }
        //    set
        //    {
        //        _SimpleRoles = value;
        //    }
        //}

        #endregion Properties

        #region Methods

        public static StifelOS FromSerializableStifelOS( SerializableStifelOS value )
        {
            StifelOS o = new StifelOS
            {
                Active = value.Active,
                Author = value.Author,
                Created = value.Created,
                Default = value.Default,
                DftCPU = value.DftCPU,
                DftHardDriveName = value.DftHardDriveName,
                DftHardDrives = value.DftHardDrives,
                DftHDSizeGB = value.DftHDSizeGB,
                DftMemoryGB = value.DftMemoryGB,
                //DftNetworkConnections = value.DftNetworkConnections,
                Editor = value.Editor,
                Id = value.Id,
                LegacyOS=value.LegacyOS,
                MaxCPU = value.MaxCPU,
                MaxHardDrives = value.MaxHardDrives,
                //MaxHDSizeGB = value.MaxHDSizeGB,
                MaxMemoryGB = value.MaxMemoryGB,
                MaxNetworkConnections = value.MaxNetworkConnections,
                Modified = value.Modified,
                OSName = value.OSName,
                Path = value.Path,
                //SimpleRoles = value.SimpleRoles,
                Server = value.Server,
                ServerRoles = value.ServerRoles,
                Title = value.Title,
                UniqueId = value.UniqueId,
                Version = value.Version
            };

            //foreach ( KeyValuePair<int, string> v in value.SimpleRoles )
            //{
            //    Item item = new Item
            //    {
            //    };
            //}

            return o;
        }

        void ICustomMapping.MapFrom( object listItem )
        {
        }

        void ICustomMapping.MapTo( object listItem )
        {
        }

        void ICustomMapping.Resolve( RefreshMode mode, object originalListItem, object databaseListItem )
        {
        }

        public SerializableStifelOS ToSerializableStifelOS( )
        {
            return new SerializableStifelOS
            {
                Active = this.Active,
                Author = this.Author,
                Created = this.Created,
                Default = this.Default,
                DftCPU = this.DftCPU,
                DftHardDriveLabel = this.DftHardDriveLabel,
                DftHardDriveName = this.DftHardDriveName,
                DftHardDrives = this.DftHardDrives,
                DftHDSizeGB = this.DftHDSizeGB,
                DftMemoryGB = this.DftMemoryGB,
                //DftNetworkConnections = this.DftNetworkConnections,
                Editor = this.Editor,
                Id = this.Id,
                MaxCPU = this.MaxCPU,
                LegacyOS = this.LegacyOS,
                MaxHardDrives = this.MaxHardDrives,
                //MaxHDSizeGB = this.MaxHDSizeGB,
                MaxMemoryGB = this.MaxMemoryGB,
                MaxNetworkConnections = this.MaxNetworkConnections,
                Modified = this.Modified,
                OSName = this.OSName,
                Path = this.Path,
                //SimpleRoles = this.SimpleRoles,
                Server = this.Server,
                ServerRoles = this.ServerRoles,
                Title = this.Title,
                UniqueId = this.UniqueId,
                Version = this.Version
            };
        }

        #endregion Methods
    }

    public partial class StifelOSRole
    {
        #region Fields

        List<string> _Subroles;

        #endregion Fields

        #region Properties

        public KeyValuePair<int, string> Key
        {
            get
            {
                return new KeyValuePair<int, string>( Id.Value, Title );
            }
        }

        public List<string> Subroles
        {
            get
            {
                if ( _Subroles == null )
                {
                    _Subroles = new List<string>( );
                    if ( !string.IsNullOrEmpty( OSSubRoles ) )
                    {
                        _Subroles = OSSubRoles.Split( new string[ ] { ";" }, StringSplitOptions.RemoveEmptyEntries ).ToList( );
                        _Subroles.ForEach( a => a.Trim( ) );
                    }
                }
                return _Subroles;
            }
        }

        #endregion Properties
    }

    public partial class StifelVirtualServerLocation
    {
        #region Fields

        List<string> _DNSAddresses;
        List<string> _WINSAddresses;

        #endregion Fields

        #region Properties

        public string CityState
        {
            get
            {
                return string.Format( "{0}, {1} ({2})", Title, USStateAbbreviation, Timezone.TimeZoneID );
            }
        }

        public List<string> DNSAddresses
        {
            get
            {
                if ( _DNSAddresses == null )
                {
                    if ( string.IsNullOrEmpty( DNS ) )
                        _DNSAddresses = new List<string>( );
                    else
                        _DNSAddresses = DNS.Split( new char[ ] { ';' }, StringSplitOptions.RemoveEmptyEntries ).ToList( );
                    _DNSAddresses.ForEach( a => a.Trim( ) );
                }
                return _DNSAddresses;
            }
        }

        public Timezone Timezone
        {
            get;
            set;
        }

        public string USStateAbbreviation
        {
            get;
            set;
        }

        public List<string> WINSAddresses
        {
            get
            {
                if ( _WINSAddresses == null )
                {
                    if ( string.IsNullOrEmpty( WINS ) )
                        _WINSAddresses = new List<string>( );
                    else
                        _WINSAddresses = WINS.Split( new char[ ] { ';' }, StringSplitOptions.RemoveEmptyEntries ).ToList( );
                    _WINSAddresses.ForEach( a => a.Trim( ) );
                }
                return _WINSAddresses;
            }
        }

        #endregion Properties

        #region Methods

        public StifelVirtualServerLocationSerizable ToSerializable( )
        {
            return new StifelVirtualServerLocationSerizable
            {
                City = Title,
                State = USStatesLookupusr_us_value,
                StateAbbrev = USStateAbbreviation,
                TimezoneId = Timezone.TimeZoneID,
                UniqueId = UniqueId
            };
        }

        #endregion Methods
    }

    [Serializable]
    public class StifelVirtualServerLocationSerizable
    {
        #region Properties

        public string City
        {
            get;
            set;
        }

        public string State
        {
            get;
            set;
        }

        public string StateAbbrev
        {
            get;
            set;
        }

        public string TimezoneId
        {
            get;
            set;
        }

        public Guid UniqueId
        {
            get;
            set;
        }

        #endregion Properties
    }

    public partial class StifelVirtualServerRequest
    {
        #region Properties

        public NotificationId NotificationIdDeserialized
        {
            get
            {
                return getNotificationIdDeserialized( );
            }
        }

        public VirtualServerCollectionClass RequestInfoDeserialized
        {
            get
            {
                return getRequestInfoDeserialized( );
            }
        }

        #endregion Properties

        #region Methods

        public bool AdvanceADConfigStatus( )
        {
            bool ok = true;
            switch ( ADConfigStatus.Value )
            {
                case Adconfigstatus.None:
                    ADConfigStatus = Adconfigstatus.Available;
                    break;
                case Adconfigstatus.Invalid:
                    ADConfigStatus = Adconfigstatus.Available;
                    break;
                case Adconfigstatus.NA:
                    ADConfigStatus = Adconfigstatus.Available;
                    break;
                case Adconfigstatus.Available:
                    ADConfigStatus = Adconfigstatus.Started;
                    break;
                case Adconfigstatus.Started:
                    ADConfigStatus = Adconfigstatus.Completed;
                    break;
                case Adconfigstatus.Completed:
                    ADConfigStatus = Adconfigstatus.Finalized;
                    ok = AdvanceFinalStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public bool AdvanceApprovalStatus( )
        {
            bool ok = true;
            switch ( ApprovalStatus.Value )
            {
                case Approvalstatus.None:
                    ApprovalStatus = Approvalstatus.Available;
                    break;
                case Approvalstatus.Invalid:
                    ApprovalStatus = Approvalstatus.Available;
                    break;
                case Approvalstatus.NA:
                    ApprovalStatus = Approvalstatus.Available;
                    break;
                case Approvalstatus.Available:
                    ApprovalStatus = Approvalstatus.Started;
                    break;
                case Approvalstatus.Started:
                    ApprovalStatus = Approvalstatus.Completed;
                    break;
                case Approvalstatus.Completed:
                    ApprovalStatus = Approvalstatus.Finalized;
                    ok = AdvanceBuildStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public bool AdvanceAVConfigStatus( )
        {
            bool ok = true;
            switch ( AVConfigStatus.Value )
            {
                case Avconfigstatus.None:
                    AVConfigStatus = Avconfigstatus.Available;
                    break;
                case Avconfigstatus.Invalid:
                    AVConfigStatus = Avconfigstatus.Available;
                    break;
                case Avconfigstatus.NA:
                    AVConfigStatus = Avconfigstatus.Available;
                    break;
                case Avconfigstatus.Available:
                    AVConfigStatus = Avconfigstatus.Started;
                    break;
                case Avconfigstatus.Started:
                    AVConfigStatus = Avconfigstatus.Completed;
                    break;
                case Avconfigstatus.Completed:
                    AVConfigStatus = Avconfigstatus.Finalized;
                    ok = AdvanceFinalStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public bool AdvanceBackupConfigStatus( )
        {
            bool ok = true;
            switch ( BackupConfigStatus.Value )
            {
                case Backupconfigstatus.None:
                    BackupConfigStatus = Backupconfigstatus.Available;
                    break;
                case Backupconfigstatus.Invalid:
                    BackupConfigStatus = Backupconfigstatus.Available;
                    break;
                case Backupconfigstatus.NA:
                    BackupConfigStatus = Backupconfigstatus.Available;
                    break;
                case Backupconfigstatus.Available:
                    BackupConfigStatus = Backupconfigstatus.Started;
                    break;
                case Backupconfigstatus.Started:
                    BackupConfigStatus = Backupconfigstatus.Completed;
                    break;
                case Backupconfigstatus.Completed:
                    BackupConfigStatus = Backupconfigstatus.Finalized;
                    ok = AdvanceFinalStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public bool AdvanceBuildStatus( )
        {
            bool ok = true;
            switch ( BuildStatus.Value )
            {
                case Buildstatus.None:
                    BuildStatus = Buildstatus.Available;
                    break;
                case Buildstatus.Invalid:
                    BuildStatus = Buildstatus.Available;
                    break;
                case Buildstatus.NA:
                    BuildStatus = Buildstatus.Available;
                    break;
                case Buildstatus.Available:
                    BuildStatus = Buildstatus.Started;
                    break;
                case Buildstatus.Started:
                    BuildStatus = Buildstatus.Completed;
                    break;
                case Buildstatus.Completed:
                    BuildStatus = Buildstatus.Finalized;
                    ok = AdvancePostBuildStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public bool AdvanceFinalStatus( )
        {
            bool ok = true;
            return ok;
        }

        public bool AdvanceMonitoringConfigStatus( )
        {
            bool ok = true;
            switch ( MonitorConfigStatus.Value )
            {
                case Monitoringconfigstatus.None:
                    MonitorConfigStatus = Monitoringconfigstatus.Available;
                    break;
                case Monitoringconfigstatus.Invalid:
                    MonitorConfigStatus = Monitoringconfigstatus.Available;
                    break;
                case Monitoringconfigstatus.NA:
                    MonitorConfigStatus = Monitoringconfigstatus.Available;
                    break;
                case Monitoringconfigstatus.Available:
                    MonitorConfigStatus = Monitoringconfigstatus.Started;
                    break;
                case Monitoringconfigstatus.Started:
                    MonitorConfigStatus = Monitoringconfigstatus.Completed;
                    break;
                case Monitoringconfigstatus.Completed:
                    MonitorConfigStatus = Monitoringconfigstatus.Finalized;
                    ok = AdvanceFinalStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public bool AdvancePatchConfigStatus( )
        {
            bool ok = true;
            switch ( PatchConfigStatus.Value )
            {
                case Patchconfigstatus.None:
                    PatchConfigStatus = Patchconfigstatus.Available;
                    break;
                case Patchconfigstatus.Invalid:
                    PatchConfigStatus = Patchconfigstatus.Available;
                    break;
                case Patchconfigstatus.NA:
                    PatchConfigStatus = Patchconfigstatus.Available;
                    break;
                case Patchconfigstatus.Available:
                    PatchConfigStatus = Patchconfigstatus.Started;
                    break;
                case Patchconfigstatus.Started:
                    PatchConfigStatus = Patchconfigstatus.Completed;
                    break;
                case Patchconfigstatus.Completed:
                    PatchConfigStatus = Patchconfigstatus.Finalized;
                    ok = AdvanceFinalStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public bool AdvancePostBuildStatus( )
        {
            bool ad = AdvanceADConfigStatus( );
            bool av = AdvanceAVConfigStatus( );
            bool bu = AdvanceBackupConfigStatus( );
            bool mn = AdvanceMonitoringConfigStatus( );
            bool pa = AdvancePatchConfigStatus( );
            return ad || av || bu || mn || pa;
        }

        public bool AdvanceRequestStatus( )
        {
            bool ok = true;
            switch ( RequestorStatus.Value )
            {
                case Requeststatus.None:
                    RequestorStatus = Requeststatus.Available;
                    break;
                case Requeststatus.Invalid:
                    RequestorStatus = Requeststatus.Available;
                    break;
                case Requeststatus.NA:
                    RequestorStatus = Requeststatus.Available;
                    break;
                case Requeststatus.Available:
                    RequestorStatus = Requeststatus.Started;
                    break;
                case Requeststatus.Started:
                    RequestorStatus = Requeststatus.Completed;
                    break;
                case Requeststatus.Completed:
                    RequestorStatus = Requeststatus.Finalized;
                    ok = AdvanceApprovalStatus( );
                    break;
                default:
                    ok = false;
                    break;
            }
            return ok;
        }

        public int Advance_ApprovalStatus( )
        {
            int i = 200;
            switch ( ApprovalStatus.Value )
            {
                case Approvalstatus.None:
                    ApprovalStatus = Approvalstatus.Available;
                    i += ( int ) Approvalstatus.Available;
                    break;
                case Approvalstatus.Invalid:
                    ApprovalStatus = Approvalstatus.Available;
                    i += ( int ) Approvalstatus.Available;
                    break;
                case Approvalstatus.NA:
                    ApprovalStatus = Approvalstatus.Available;
                    i += ( int ) Approvalstatus.Available;
                    break;
                case Approvalstatus.Available:
                    ApprovalStatus = Approvalstatus.Started;
                    i += ( int ) Approvalstatus.Started;
                    break;
                case Approvalstatus.Started:
                    ApprovalStatus = Approvalstatus.Completed;
                    i += ( int ) Approvalstatus.Completed;
                    break;
                case Approvalstatus.Completed:
                    ApprovalStatus = Approvalstatus.Finalized;
                    i += ( int ) Approvalstatus.Finalized;
                    break;
                case Approvalstatus.Finalized:
                    i = Advance_BuildStatus( );
                    break;
                default:
                    break;
            }
            return i;
        }

        public int Advance_BackupConfigStatus( )
        {
            int i = 400;
            switch ( BackupConfigStatus.Value )
            {
                case Backupconfigstatus.None:
                    BackupConfigStatus = Backupconfigstatus.Available;
                    i += ( int ) Backupconfigstatus.Available;
                    break;
                case Backupconfigstatus.Invalid:
                    BackupConfigStatus = Backupconfigstatus.Available;
                    i += ( int ) Backupconfigstatus.Available;
                    break;
                case Backupconfigstatus.NA:
                    BackupConfigStatus = Backupconfigstatus.Available;
                    i += ( int ) Backupconfigstatus.Available;
                    break;
                case Backupconfigstatus.Available:
                    BackupConfigStatus = Backupconfigstatus.Started;
                    i += ( int ) Backupconfigstatus.Started;
                    break;
                case Backupconfigstatus.Started:
                    BackupConfigStatus = Backupconfigstatus.Completed;
                    i += ( int ) Backupconfigstatus.Completed;
                    break;
                case Backupconfigstatus.Completed:
                    BackupConfigStatus = Backupconfigstatus.Finalized;
                    i += ( int ) Backupconfigstatus.Finalized;
                    break;
                case Backupconfigstatus.Finalized:
                    break;
                default:
                    break;
            }

            return i;
        }

        public int Advance_BuildStatus( )
        {
            int i = 300;
            switch ( BuildStatus.Value )
            {
                case Buildstatus.None:
                    BuildStatus = Buildstatus.Available;
                    i += ( int ) Buildstatus.Available;
                    break;
                case Buildstatus.Invalid:
                    BuildStatus = Buildstatus.Available;
                    i += ( int ) Buildstatus.Available;
                    break;
                case Buildstatus.NA:
                    BuildStatus = Buildstatus.Available;
                    i += ( int ) Buildstatus.Available;
                    break;
                case Buildstatus.Available:
                    BuildStatus = Buildstatus.Started;
                    i += ( int ) Buildstatus.Started;
                    break;
                case Buildstatus.Started:
                    BuildStatus = Buildstatus.Completed;
                    i += ( int ) Buildstatus.Completed;
                    break;
                case Buildstatus.Completed:
                    BuildStatus = Buildstatus.Finalized;
                    i += ( int ) Buildstatus.Finalized;
                    break;
                case Buildstatus.Finalized:
                    break;
                default:
                    break;
            }

            return i;
        }

        public int Advance_RequestStatus( )
        {
            int i = 100;
            switch ( RequestorStatus.Value )
            {
                case Requeststatus.None:
                    RequestorStatus = Requeststatus.Available;
                    i += ( int ) Requeststatus.Available;
                    break;
                case Requeststatus.Invalid:
                    RequestorStatus = Requeststatus.Available;
                    i += ( int ) Requeststatus.Available;
                    break;
                case Requeststatus.NA:
                    RequestorStatus = Requeststatus.Available;
                    i += ( int ) Requeststatus.Available;
                    break;
                case Requeststatus.Available:
                    RequestorStatus = Requeststatus.Started;
                    i += ( int ) Requeststatus.Started;
                    break;
                case Requeststatus.Started:
                    RequestorStatus = Requeststatus.Completed;
                    i += ( int ) Requeststatus.Completed;
                    break;
                case Requeststatus.Completed:
                    RequestorStatus = Requeststatus.Finalized;
                    i += ( int ) Requeststatus.Finalized;
                    break;
                case Requeststatus.Finalized:
                    i = Advance_ApprovalStatus( );
                    break;
                default:
                    break;
            }

            return i;
        }

        public bool getADStatus( )
        {
            bool ret = false;
            if ( ( ADConfigStatus == Adconfigstatus.Started ) || ( ADConfigStatus == Adconfigstatus.Available ) )
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
            return ( ret );
        }

        public bool getAntiVirusStatus( )
        {
            bool ret = false;
            if ( ( AVConfigStatus == Avconfigstatus.Started ) || ( AVConfigStatus == Avconfigstatus.Available ) )
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
            return ( ret );
        }

        public bool getApprovalStatus( )
        {
            bool ret = false;
            if ( ( ApprovalStatus == Approvalstatus.Started ) || ( ApprovalStatus == Approvalstatus.Available ) )
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
            return ( ret );
        }

        public bool getBackUpStatus( )
        {
            bool ret = false;
            if ( ( BackupConfigStatus == Backupconfigstatus.Started ) || ( BackupConfigStatus == Backupconfigstatus.Available ) )
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
            return ( ret );
        }

        public bool getBuildStatus( )
        {
            bool ret = false;
            if ( ( BuildStatus == Buildstatus.Available ) || ( BuildStatus == Buildstatus.Started ) )
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
            return ( ret );
        }

        public bool getMoniteringNetworkStatus( )
        {
            bool ret = false;
            if ( ( MonitorConfigStatus == Monitoringconfigstatus.Started ) || ( MonitorConfigStatus == Monitoringconfigstatus.Available ) )
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
            return ( ret );
        }

        public bool getPatchStatus( )
        {
            bool ret = false;
            if ( ( PatchConfigStatus == Patchconfigstatus.Started ) || ( PatchConfigStatus == Patchconfigstatus.Available ) )
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
            return ( ret );
        }

        public VirtualServerCollectionClass getRequestInfoDeserialized( )
        {
            string STARTTAG = "<Request>".HtmlEncode( );
            string ENDTAG = "</Request>".HtmlEncode( );
            string s = string.Empty;
            if ( !string.IsNullOrEmpty( SerializedVirtualServerRequest ) )
            {
                int a = SerializedVirtualServerRequest.IndexOf( STARTTAG );
                int b = SerializedVirtualServerRequest.IndexOf( ENDTAG ) + ENDTAG.Length;
                int c = SerializedVirtualServerRequest.Length;
                s = SerializedVirtualServerRequest.Substring( a, c - a - ( c - b ) );
            }
            VirtualServerCollectionClass request = null;
            if ( !string.IsNullOrEmpty( s ) )
                request = s.HtmlDecode( ).DeserializeFromXml<VirtualServerCollectionClass>( );
            if ( request == null )
                request = new VirtualServerCollectionClass( );
            return request;
        }

        public bool getRequestStatus( )
        {
            bool ret = false;
            if ( RequestorStatus == Requeststatus.Started )
            {
                ret = true;
            }
            else if ( RequestorStatus == Requeststatus.Completed )
            {
                ret = false;
            }
            else
            {
            }
            return ( ret );
        }

        public bool IsADConfigActive( )
        {
            if ( ADConfigStatus == Adconfigstatus.Available ||
                ADConfigStatus == Adconfigstatus.Completed ||
                ADConfigStatus == Adconfigstatus.Started
            )
                return true;
            else
                return false;
        }

        public bool IsADConfigAvailable( )
        {
            return ADConfigStatus == Adconfigstatus.Available;
        }

        public bool IsADConfigCompleted( )
        {
            return ADConfigStatus == Adconfigstatus.Completed;
        }

        public bool IsADConfigFinalized( )
        {
            return ADConfigStatus == Adconfigstatus.Finalized;
        }

        public bool IsADConfigNA( )
        {
            switch ( ADConfigStatus.Value )
            {
                case Adconfigstatus.None:
                case Adconfigstatus.Invalid:
                case Adconfigstatus.NA:
                    return true;
                default:
                    return false;
            }
        }

        public bool IsADConfigStarted( )
        {
            return ADConfigStatus == Adconfigstatus.Started;
        }

        public bool IsApprovalAvailable( )
        {
            return ApprovalStatus == Approvalstatus.Available;
        }

        public bool IsApprovalCompleted( )
        {
            return ApprovalStatus == Approvalstatus.Completed;
        }

        public bool IsApprovalFinalized( )
        {
            return ApprovalStatus == Approvalstatus.Finalized;
        }

        public bool IsApprovalNA( )
        {
            switch ( ApprovalStatus.Value )
            {
                case Approvalstatus.None:
                case Approvalstatus.Invalid:
                case Approvalstatus.NA:
                    return true;
                default:
                    return false;
            }
        }

        public bool IsApprovalStarted( )
        {
            return ApprovalStatus == Approvalstatus.Started;
        }

        public bool IsAVConfigActive( )
        {
            if ( AVConfigStatus == Avconfigstatus.Available ||
                AVConfigStatus == Avconfigstatus.Completed ||
                AVConfigStatus == Avconfigstatus.Started
            )
                return true;
            else
                return false;
        }

        public bool IsAVConfigAvailable( )
        {
            return AVConfigStatus == Avconfigstatus.Available;
        }

        public bool IsAVConfigCompleted( )
        {
            return AVConfigStatus == Avconfigstatus.Completed;
        }

        public bool IsAVConfigFinalized( )
        {
            return AVConfigStatus == Avconfigstatus.Finalized;
        }

        public bool IsAVConfigNA( )
        {
            switch ( AVConfigStatus.Value )
            {
                case Avconfigstatus.None:
                case Avconfigstatus.Invalid:
                case Avconfigstatus.NA:
                    return true;
                default:
                    return false;
            }
        }

        public bool IsAVConfigStarted( )
        {
            return AVConfigStatus == Avconfigstatus.Started;
        }

        public bool IsBackupConfigActive( )
        {
            if ( BackupConfigStatus == Backupconfigstatus.Available ||
                BackupConfigStatus == Backupconfigstatus.Completed ||
                BackupConfigStatus == Backupconfigstatus.Started
            )
                return true;
            else
                return false;
        }

        public bool IsBackupConfigAvailable( )
        {
            return BackupConfigStatus == Backupconfigstatus.Available;
        }

        public bool IsBackupConfigCompleted( )
        {
            return BackupConfigStatus == Backupconfigstatus.Completed;
        }

        public bool IsBackupConfigFinalized( )
        {
            return BackupConfigStatus == Backupconfigstatus.Finalized;
        }

        public bool IsBackupConfigNA( )
        {
            switch ( BackupConfigStatus.Value )
            {
                case Backupconfigstatus.None:
                case Backupconfigstatus.Invalid:
                case Backupconfigstatus.NA:
                    return true;
                default:
                    return false;
            }
        }

        public bool IsBackupConfigStarted( )
        {
            return BackupConfigStatus == Backupconfigstatus.Started;
        }

        public bool IsBuildActive( )
        {
            if ( BuildStatus == Buildstatus.Available ||
                BuildStatus == Buildstatus.Completed ||
                BuildStatus == Buildstatus.Started
            )
                return true;
            else
                return false;
        }

        public bool IsBuildAvailable( )
        {
            return BuildStatus == Buildstatus.Available;
        }

        public bool IsBuildCompleted( )
        {
            return BuildStatus == Buildstatus.Completed;
        }

        public bool IsBuildFinalized( )
        {
            return BuildStatus == Buildstatus.Finalized;
        }

        public bool IsBuildNA( )
        {
            switch ( BuildStatus.Value )
            {
                case Buildstatus.None:
                case Buildstatus.Invalid:
                case Buildstatus.NA:
                    return true;
                default:
                    return false;
            }
        }

        public bool IsBuildStarted( )
        {
            return BuildStatus == Buildstatus.Started;
        }

        public bool IsConfigCompleted( )
        {
            if ( ADConfigStatus == Adconfigstatus.Finalized &&
                AVConfigStatus == Avconfigstatus.Finalized &&
                BackupConfigStatus == Backupconfigstatus.Finalized &&
                MonitorConfigStatus == Monitoringconfigstatus.Finalized &&
                PatchConfigStatus == Patchconfigstatus.Finalized
            )
                return true;
            else
                return false;
        }

        public bool IsInApprovalState( )
        {
            if ( ApprovalStatus == Approvalstatus.Available ||
                ApprovalStatus == Approvalstatus.Completed ||
                ApprovalStatus == Approvalstatus.Started || (
                    ApprovalStatus == Approvalstatus.Finalized &&
                    IsBuildNA( )
                )
            )
                return true;
            else
                return false;
        }

        public bool IsInBuildState( )
        {
            if ( IsBuildActive( ) ||
                ( BuildStatus == Buildstatus.Finalized &&
                    (
                        IsADConfigNA( ) &&
                        IsAVConfigNA( ) &&
                        IsBackupConfigNA( ) &&
                        IsMonitoringConfigNA( ) &&
                        IsPatchConfigNA( )
                    )
                )
            )
                return true;
            else
                return false;
        }

        public bool IsInInitialRequestState( )
        {
            if ( RequestorStatus == Requeststatus.Available ||
                RequestorStatus == Requeststatus.Completed ||
                RequestorStatus == Requeststatus.Started || (
                    RequestorStatus == Requeststatus.Finalized &&
                    IsApprovalNA( )
                )
            )
                return true;
            else
                return false;
        }

        public bool IsInPostBuildState( )
        {
            if ( IsADConfigActive( ) ||
                IsAVConfigActive( ) ||
                IsBackupConfigActive( ) ||
                IsMonitoringConfigActive( ) ||
                IsPatchConfigActive( )
            )
                return true;
            else
                return false;
        }

        public bool IsMonitoringConfigActive( )
        {
            if ( MonitorConfigStatus == Monitoringconfigstatus.Available ||
                MonitorConfigStatus == Monitoringconfigstatus.Completed ||
                MonitorConfigStatus == Monitoringconfigstatus.Started
            )
                return true;
            else
                return false;
        }

        public bool IsMonitoringConfigAvailable( )
        {
            return MonitorConfigStatus == Monitoringconfigstatus.Available;
        }

        public bool IsMonitoringConfigCompleted( )
        {
            return MonitorConfigStatus == Monitoringconfigstatus.Completed;
        }

        public bool IsMonitoringConfigFinalized( )
        {
            return MonitorConfigStatus == Monitoringconfigstatus.Finalized;
        }

        public bool IsMonitoringConfigNA( )
        {
            switch ( MonitorConfigStatus.Value )
            {
                case Monitoringconfigstatus.None:
                case Monitoringconfigstatus.Invalid:
                case Monitoringconfigstatus.NA:
                    return true;
                default:
                    return false;
            }
        }

        public bool IsMonitoringConfigStarted( )
        {
            return MonitorConfigStatus == Monitoringconfigstatus.Started;
        }

        public bool IsPatchConfigActive( )
        {
            if ( PatchConfigStatus == Patchconfigstatus.Available ||
                PatchConfigStatus == Patchconfigstatus.Completed ||
                PatchConfigStatus == Patchconfigstatus.Started
            )
                return true;
            else
                return false;
        }

        public bool IsPatchConfigAvailable( )
        {
            return PatchConfigStatus == Patchconfigstatus.Available;
        }

        public bool IsPatchConfigCompleted( )
        {
            return PatchConfigStatus == Patchconfigstatus.Completed;
        }

        public bool IsPatchConfigFinalized( )
        {
            return PatchConfigStatus == Patchconfigstatus.Finalized;
        }

        public bool IsPatchConfigNA( )
        {
            switch ( PatchConfigStatus.Value )
            {
                case Patchconfigstatus.None:
                case Patchconfigstatus.Invalid:
                case Patchconfigstatus.NA:
                    return true;
                default:
                    return false;
            }
        }

        public bool IsPatchConfigStarted( )
        {
            return PatchConfigStatus == Patchconfigstatus.Started;
        }

        public bool IsRequestorCompleted( )
        {
            return RequestorStatus == Requeststatus.Completed;
        }

        public bool IsRequestorFinalized( )
        {
            if ( RequestorStatus == Requeststatus.Finalized &&
                IsApprovalNA( )
            )
                return true;
            else
                return false;
        }

        public bool IsRequestorStarted( )
        {
            return RequestorStatus == Requeststatus.Started;
        }

        public string SerializeNotificationId( NotificationId v )
        {
            string s = string.Empty;
            if ( v != null )
                s = v.SerializeToXml<NotificationId>( ).HtmlEncode( );
            return s;
        }

        public string SerializeVirtualServerCollectionClass( VirtualServerCollectionClass v )
        {
            string s = string.Empty;
            if ( v != null )
                s = v.SerializeToXml<VirtualServerCollectionClass>( ).HtmlEncode( );
            return s;
        }

        public void SetForADSave( )
        {
            ADConfigStatus = Adconfigstatus.Started;
            Control = true;
        }

        public void SetForADSubmit( )
        {
            ADConfigStatus = Adconfigstatus.Completed;
            Control = true;
        }

        public void SetForAntiVirusSave( )
        {
            AVConfigStatus = Avconfigstatus.Started;
            Control = true;
        }

        public void SetForAntiVirusSubmit( )
        {
            AVConfigStatus = Avconfigstatus.Completed;
            Control = true;
        }

        public void SetForApproveSave( )
        {
            ApprovalStatus = Approvalstatus.Started;
            Control = true;
        }

        public void SetForBackUpSave( )
        {
            BackupConfigStatus = Backupconfigstatus.Started;
            Control = true;
        }

        public void SetForBackUpSubmit( )
        {
            BackupConfigStatus = Backupconfigstatus.Completed;
            Control = true;
        }

        public void SetForBuildSave( )
        {
            BuildStatus = Buildstatus.Started;
            Control = true;
        }

        public void SetForBuildSubmit( )
        {
            BuildStatus = Buildstatus.Completed;
            Control = true;
        }

        public void SetForMoniteringNetworkSave( )
        {
            MonitorConfigStatus = Monitoringconfigstatus.Started;
            Control = true;
        }

        public void SetForMoniteringNetworkSubmit( )
        {
            MonitorConfigStatus = Monitoringconfigstatus.Completed;
            Control = true;
        }

        public void SetForPatchSave( )
        {
            PatchConfigStatus = Patchconfigstatus.Started;
            Control = true;
        }

        public void SetForPatchSubmit( )
        {
            PatchConfigStatus = Patchconfigstatus.Completed;
            Control = true;
        }

        public void SetForRequestApprove( )
        {
            RequestApproved = true;
            RequestRejected = false;
            ApprovalStatus = Approvalstatus.Completed;
            Control = true;
        }

        public void SetForRequestSave( )
        {
            RequestorStatus = Requeststatus.Started;
            Control = true;
        }

        public void SetForRequestSubmit( )
        {
            RequestorStatus = Requeststatus.Completed;
            Control = true;
        }

        public void SetRequestRejected( )
        {
            RequestApproved = false;
            RequestRejected = true;
            ApprovalStatus = Approvalstatus.Completed;
            Control = true;
        }

        public void Update( )
        {
            StifelServerBuildDao dao = new StifelServerBuildDao( );
            dao.Update( this );
        }

        NotificationId getNotificationIdDeserialized( )
        {
            string STARTTAG = "<NotificationId>".HtmlEncode( );
            string ENDTAG = "</NotificationId>".HtmlEncode( );
            string s = string.Empty;
            if ( !string.IsNullOrEmpty( NotificationId ) )
            {
                int a = NotificationId.IndexOf( STARTTAG );
                int b = NotificationId.IndexOf( ENDTAG ) + ENDTAG.Length;
                int c = NotificationId.Length;
                s = NotificationId.Substring( a, c - a - ( c - b ) );
            }
            NotificationId o = null;
            if ( !string.IsNullOrEmpty( s ) )
                o = s.HtmlDecode( ).DeserializeFromXml<NotificationId>( );
            if ( o == null )
                o = new NotificationId( );
            return o;
        }

        #endregion Methods
    }

    public partial class StifelVirtualServerRequestConfiguration
    {
        #region Fields

        const string REQUESTID = "@requestid";
        const string REQUESTUNIQUEID = "@requestuniqueid";
        const string REQUESTURL = "@requesturl";

        #endregion Fields

        #region Enumerations

        public enum Area : int
        {
            AD,
            Approval,
            AV,
            Backup,
            Build,
            Monitor,
            Patch,
            Requestor,
            RequestAccepted,
            RequestRejected,
            RequestCompleted
        }

        #endregion Enumerations

        #region Properties

        public string ADPageURLDescription
        {
            get
            {
                string[ ] s = ADPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string ADPageURLUrl
        {
            get
            {
                string[ ] s = ADPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string ADSiteURLDescription
        {
            get
            {
                string[ ] s = ADSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string ADSiteURLUrl
        {
            get
            {
                string[ ] s = ADSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string ApprovalPageURLDescription
        {
            get
            {
                string[ ] s = ApprovalPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string ApprovalPageURLUrl
        {
            get
            {
                string[ ] s = ApprovalPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string ApprovalSiteURLDescription
        {
            get
            {
                string[ ] s = ApprovalSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string ApprovalSiteURLUrl
        {
            get
            {
                string[ ] s = ApprovalSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string AVPageURLDescription
        {
            get
            {
                string[ ] s = AVPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string AVPageURLUrl
        {
            get
            {
                string[ ] s = AVPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string AVSiteURLDescription
        {
            get
            {
                string[ ] s = AVSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string AVSiteURLUrl
        {
            get
            {
                string[ ] s = AVSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BackupPageURLDescription
        {
            get
            {
                string[ ] s = BackupPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BackupPageURLUrl
        {
            get
            {
                string[ ] s = BackupPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BackupSiteURLDescription
        {
            get
            {
                string[ ] s = BackupSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BackupSiteURLUrl
        {
            get
            {
                string[ ] s = BackupSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BuildPageURLDescription
        {
            get
            {
                string[ ] s = BuildPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BuildPageURLUrl
        {
            get
            {
                string[ ] s = BuildPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BuildSiteURLDescription
        {
            get
            {
                string[ ] s = BuildSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string BuildSiteURLUrl
        {
            get
            {
                string[ ] s = BuildSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string MonitorPageURLDescription
        {
            get
            {
                string[ ] s = MonitorPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string MonitorPageURLUrl
        {
            get
            {
                string[ ] s = MonitorPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string MonitorSiteURLDecription
        {
            get
            {
                string[ ] s = MonitorSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string MonitorSiteURLUrl
        {
            get
            {
                string[ ] s = MonitorSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string PatchPageURLDescription
        {
            get
            {
                string[ ] s = PatchPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string PatchPageURLUrl
        {
            get
            {
                string[ ] s = PatchPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string PatchSiteURLDescription
        {
            get
            {
                string[ ] s = PatchSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string PatchSiteURLUrl
        {
            get
            {
                string[ ] s = PatchSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string RequestorPageURLDescription
        {
            get
            {
                string[ ] s = RequestorPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 1 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string RequestorPageURLUrl
        {
            get
            {
                string[ ] s = RequestorPageURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        public string RequestorSiteURLUrl
        {
            get
            {
                string[ ] s = RequestSiteURL.Split( ',' );
                if ( s.Length >= 1 )
                    return s[ 0 ].Trim( );
                else
                    return string.Empty;
            }
        }

        #endregion Properties

        #region Methods

        public string FormatNotification( Area area, int? requestId, Guid requestUniqueId )
        {
            string s = string.Empty;
            switch ( area )
            {
                case Area.AD:
                    s = formatNotification( ADNotificationTemplate, ADPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Approval:
                    s = formatNotification( ApprovalNotificationTemplate, ApprovalPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.AV:
                    s = formatNotification( AVNotificationTemplate, AVPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Backup:
                    s = formatNotification( BackupNotificationTemplate, BackupPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Build:
                    s = formatNotification( BuildNotificationTemplate, BuildPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Monitor:
                    s = formatNotification( MonitorNotificationTemplate, MonitorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Patch:
                    s = formatNotification( PatchNotificationTemplate, PatchPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Requestor:
                    s = formatNotification( RequestNotificationTemplate, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.RequestAccepted:
                    s = formatNotification( RequestAcceptedNotificationTemplate, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.RequestRejected:
                    s = formatNotification( RequestRejectedNotificationTemplate, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.RequestCompleted:
                    s = formatNotification( RequestCompletedNotificationTemplate, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                default:
                    break;
            }
            return s;
        }

        public string FormatNotificationTitle( Area area, int? requestId, Guid requestUniqueId )
        {
            string s = string.Empty;
            switch ( area )
            {
                case Area.AD:
                    s = formatNotificationTitle( ADNotificationTitle, ADPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Approval:
                    s = formatNotificationTitle( ApprovalNotificationTitle, ApprovalPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.AV:
                    s = formatNotificationTitle( AVNotificationTitle, AVPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Backup:
                    s = formatNotificationTitle( BackupNotificationTitle, BackupPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Build:
                    s = formatNotificationTitle( BuildNotificationTitle, BuildPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Monitor:
                    s = formatNotificationTitle( MonitorNotificationTitle, MonitorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Patch:
                    s = formatNotificationTitle( PatchNotificationTitle, PatchPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.Requestor:
                    s = formatNotificationTitle( RequestNotificationTitle, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.RequestAccepted:
                    s = formatNotificationTitle( RequestAcceptedNotificationTitle, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.RequestRejected:
                    s = formatNotificationTitle( RequestRejectedNotificationTitle, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                case Area.RequestCompleted:
                    s = formatNotificationTitle( RequestCompletionNotificationTitle, RequestorPageURLUrl, requestId, requestUniqueId );
                    break;
                default:
                    break;
            }
            return s;
        }

        public string FormatPageUrl( Area area, Guid requestUniqueId )
        {
            string s = string.Empty;
            switch ( area )
            {
                case Area.AD:
                    s = formatPageUrl( ADPageURLUrl, requestUniqueId );
                    break;
                case Area.Approval:
                    s = formatPageUrl( ApprovalPageURLUrl, requestUniqueId );
                    break;
                case Area.AV:
                    s = formatPageUrl( AVPageURLUrl, requestUniqueId );
                    break;
                case Area.Backup:
                    s = formatPageUrl( BackupPageURLUrl, requestUniqueId );
                    break;
                case Area.Build:
                    s = formatPageUrl( BuildPageURLUrl, requestUniqueId );
                    break;
                case Area.Monitor:
                    s = formatPageUrl( MonitorPageURLUrl, requestUniqueId );
                    break;
                case Area.Patch:
                    s = formatPageUrl( PatchPageURLUrl, requestUniqueId );
                    break;
                case Area.Requestor:
                    s = formatPageUrl( RequestorPageURLUrl, requestUniqueId );
                    break;
                default:
                    break;
            }
            return s;
        }

        public List<MailAddress> GetSecurityGroupEmailAddresses( Area area, string siteUrl )
        {
            List<MailAddress> addresses = new List<MailAddress>( );
            switch ( area )
            {
                case Area.AD:
                    addresses = getSecurityGroupEmailAddresses( siteUrl, ADSecurityGroupImnName );
                    break;
                case Area.Approval:
                    addresses = getSecurityGroupEmailAddresses( siteUrl, ApprovalSecurityGroupImnName );
                    break;
                case Area.AV:
                    addresses = getSecurityGroupEmailAddresses( siteUrl, AVSecurityGroupImnName );
                    break;
                case Area.Backup:
                    addresses = getSecurityGroupEmailAddresses( siteUrl, BackupSecurityGroupImnName );
                    break;
                case Area.Build:
                    addresses = getSecurityGroupEmailAddresses( siteUrl, BuildSecurityGroupImnName );
                    break;
                case Area.Monitor:
                    addresses = getSecurityGroupEmailAddresses( siteUrl, MonitorSecurityGroupImnName );
                    break;
                case Area.Patch:
                    addresses = getSecurityGroupEmailAddresses( siteUrl, PatchSecurityGroupImnName );
                    break;
                case Area.Requestor:
                    break;
                default:
                    break;
            }
            return addresses;
        }

        public List<SPUserInfoExpanded> GetSecurityGroupUsers( Area area, string siteUrl )
        {
            List<SPUserInfoExpanded> users = new List<SPUserInfoExpanded>( );
            switch ( area )
            {
                case Area.AD:
                    users = getSecurityGroupUsers( siteUrl, ADSecurityGroupImnName );
                    break;
                case Area.Approval:
                    users = getSecurityGroupUsers( siteUrl, ApprovalSecurityGroupImnName );
                    break;
                case Area.AV:
                    users = getSecurityGroupUsers( siteUrl, AVSecurityGroupImnName );
                    break;
                case Area.Backup:
                    users = getSecurityGroupUsers( siteUrl, BackupSecurityGroupImnName );
                    break;
                case Area.Build:
                    users = getSecurityGroupUsers( siteUrl, BuildSecurityGroupImnName );
                    break;
                case Area.Monitor:
                    users = getSecurityGroupUsers( siteUrl, MonitorSecurityGroupImnName );
                    break;
                case Area.Patch:
                    users = getSecurityGroupUsers( siteUrl, PatchSecurityGroupImnName );
                    break;
                case Area.Requestor:
                    break;
                default:
                    break;
            }
            return users;
        }

        string formatNotification( string template, string pageUrl, int? id, Guid uniqueId )
        {
            return template.Replace( REQUESTID, id.ToString( ) ).Replace( REQUESTUNIQUEID, uniqueId.ToString( "d" ) ).Replace( REQUESTURL, string.Format( "<a href=\"{0}\">Virtual Server Request {1}</a>", formatPageUrl( pageUrl, uniqueId ), id.ToString( ) ) );
        }

        string formatNotificationTitle( string title, string pageUrl, int? id, Guid uniqueId )
        {
            return title.Replace( REQUESTID, id.ToString( ) ).Replace( REQUESTUNIQUEID, uniqueId.ToString( "d" ) ).Replace( REQUESTURL, string.Format( "<a href=\"{0}\">Virtual Server Request {1}</a>", formatPageUrl( pageUrl, uniqueId ), id.ToString( ) ) );
        }

        string formatPageUrl( string url, Guid uniqueId )
        {
            if ( !string.IsNullOrEmpty( url ) )
                return string.Format( "{0}?ItemGuid={1}", url, uniqueId.ToString( "d" ) );
            return string.Empty;
        }

        List<MailAddress> getSecurityGroupEmailAddresses( string siteUrl, string groupName )
        {
            List<MailAddress> addresses = new List<MailAddress>( );
            if ( !string.IsNullOrEmpty( groupName ) )
            {
                List<SPUserInfoExpanded> users = getSecurityGroupUsers( siteUrl, groupName );
                if ( users.Count > 0 )
                    users.ForEach( a => addresses.Add( new MailAddress( a.Email, string.IsNullOrEmpty( a.Name ) ? a.LoginName : a.Name ) ) );
            }
            return addresses;
        }

        List<SPUserInfoExpanded> getSecurityGroupUsers( string siteUrl, string groupName )
        {
            List<SPUserInfoExpanded> users = new List<SPUserInfoExpanded>( );
            if ( !string.IsNullOrEmpty( groupName ) )
            {
                using ( SPSite spSite = new SPSite( siteUrl ) )
                {
                    using ( SPWeb spWeb = spSite.OpenWeb( ) )
                    {
                        IEnumerable<SPGroup> g = spWeb.SiteGroups.Cast<SPGroup>( );
                        SPGroup group = g.First( a => a.Name.Equals( groupName, StringComparison.OrdinalIgnoreCase ) );
                        if ( group != null )
                        {
                            foreach ( SPUser u in group.Users )
                            {
                                if ( u != null )
                                    users.Add( new SPUserInfoExpanded
                                    {
                                        Email = u.Email,
                                        Id = u.ID,
                                        LoginName = u.LoginName,
                                        Name = u.Name,
                                        Notes = u.Notes,
                                        Sid = u.Sid
                                    } );
                            }
                        }
                    }
                }
            }
            return users;
        }

        #endregion Methods
    }

    public partial class StifelVLAN
    {
        #region Properties

        public string VlanInfo
        {
            get
            {
                return ( string.Format( "{0}-{1} ({2})", Title, VLANId.ToString( ), VLANIp ) );
            }
        }

        #endregion Properties

        #region Methods

        public StifelVLANSerializable ToSrializable( )
        {
            return new StifelVLANSerializable
            {
                stifelVlanInfo = VlanInfo,
                stifelVlanTitle = Title,
                stifelVlanId = VLANId,
                stifelVlanIp = VLANIp,
                stifelVlanClusterId = ClusterId,
                stifelVlanClusterTitle = ClusterTitle,
                stifelVlanLocationId = LocationId,
                stifelVlanLocationTitle = LocationTitle
            };
        }

        #endregion Methods
    }

    [Serializable]
    public class StifelVLANSerializable
    {
        #region Properties

        public int? stifelVlanClusterId
        {
            get;
            set;
        }

        public string stifelVlanClusterTitle
        {
            get;
            set;
        }

        public double? stifelVlanId
        {
            get;
            set;
        }

        public string stifelVlanInfo
        {
            get;
            set;
        }

        public string stifelVlanIp
        {
            get;
            set;
        }

        public int? stifelVlanLocationId
        {
            get;
            set;
        }

        public string stifelVlanLocationTitle
        {
            get;
            set;
        }

        public string stifelVlanTitle
        {
            get;
            set;
        }

        #endregion Properties
    }
}